# 备份到指定的文件夹
BACKUP_DIR=/mnt/g/Stu/42_Hardware/

# ------------------------------------------------

IMAGES_ID=158e3b2aef4c
CHECK_ID=$(shell docker images |grep $(IMAGES_ID))

default:run 


run:check
	bash clear.sh
	mkdir -p db public_media uploads
	docker-compose up -d 
	docker exec --user=www-data partdb php bin/console doctrine:migrations:migrate

# 判断docker IMAGES_ID 是否存在image
check:
	@echo "Check docker image ......"
ifeq ($(CHECK_ID),)
	@echo "Exist image id $(IMAGES_ID), try to load hp-partdb.tar"
	make load_image
else 
	@echo "Exist image id $(IMAGES_ID)"
endif 


save_image:
ifeq ($(wildcard hp-partdb.tar),)
	@echo "export hp-partdb "
	docker save $(IMAGES_ID) > hp-partdb.tar
endif 


load_image:
ifeq ($(wildcard hp-partdb.tar),)
	@echo "You should get hp-partdb.tar from network ...... "
	@echo "URL: https://caiyun.139.com/w/i/2oxwFbadNAM0t"
	@echo "jymi"
	@exit 1
endif 
	# docker load <  hp-partdb.tar
	# docker tag $(IMAGES_ID) hp-partdb

backup:
	@echo "Backup my partdb ......"
	cp $(shell pwd)  $(BACKUP_DIR) -R

help:
	@echo "--------------------------------------------------"
	@echo "make backup        备份到$(BACKUP_DIR)"
	@echo "make               自动导入docker镜像并开启服务器"
	@echo "make save_image    保存镜像"
	@echo "make help          显示帮助"
	@echo "--------------------------------------------------"

